﻿using System.Text;
using System.Data;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;
using ChannelVN.Cached.Base;
using BugManager;

namespace GUI.Controls.News
{
    public partial class Slide : ControlBase
    {
        #region Overrides of ControlBase

        public override string CacheConfigName
        {
            get { return "Controls-News-Slide"; }
        }

        public override bool IsCachedChanged(long newsId, string zoneId, long tagId)
        {
            return !string.IsNullOrEmpty(zoneId);
        }

        #endregion

        private const int ImageWidth = 115;
        private const int ImageHeight = 90;
        private const string LiFormat = "<li class=\"fl\">{3}" +
            //"<span class=\"subject2\">{5}</span>" +
                    "<p><a href=\"{0}\" title=\"{2}\">{1}</a></p>" +
            //"<span class=\"date2\">{4}</span>"+
                    "</li>";



        internal bool DataBind(DataTable dt)
        {

            if (dt != null && dt.Rows.Count > 0)
            {
                var sb = new StringBuilder();
                foreach (DataRow r in dt.Rows)
                {
                    var avatar = PresentationUtils.Photo.BuildNewsAvatar(r, ImageWidth, ImageHeight);

                    sb.AppendFormat(LiFormat,
                        r[SqlConstants.NewsPublish.Url],
                        r[SqlConstants.NewsPublish.Title],
                        r[SqlConstants.NewsPublish.EncodedTitle],
                        avatar//,
                        //PresentationUtils.Object2DateTime(r[SqlConstants.NewsPublish.DistributionDate].ToString()).ToString("dd/MM/yyyy HH:mm")
                        );
                }
                ltrData.Text = sb.ToString();
                return true;
            }
            return false;
        }
    }
}